﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Maknys.Consultator.ServiceContracts;
using Maknys.Consultator.DataContracts;
using Maknys.Consultator.DomainModel;
using Maknys.Consultator.Repositories;
using System.Collections;

namespace Maknys.Consultator.Services
{
    public class TreeService : ITreeService
    {
        private readonly Tree<Element> tree;
        private Root mainRoot;
        private TreeNode<Element> root;
        private readonly ITreeRepository treeRepository;
        private IEditingService editingService;
        private ArrayList infoList = new ArrayList();

        public TreeService()
        {
            tree = new Tree<Element>();
            treeRepository = new TreeRepository();
            editingService = new EditingService();
        }
        
        public void MakeTree()
        {
            root = tree;
            Element element0 = new Element();
            string id = "1";
            string pId = "0";
            string value = "Questions";
            element0.PId = pId;
            element0.Id = id;
            element0.Value = value;
            root.Value = element0;
            mainRoot = new Root(root);
            infoList.Clear();
            editingService.ReadAll(infoList);
        }

        public void FillTree()
        {
            treeRepository.FillTree(infoList, root);
        }

        public List<string> GetElementList(string sentence)
        {
            List<string> list = new List<string>();
            list.Clear();
            list = treeRepository.GetList(root, sentence);
            return list;
        }

    }
}
